//
//  HOTMemoListCell.m
//  Genpara
//
//  Created by AndyChang.zhang on 14-9-22.
//  Copyright (c) 2014年 zhangchh. All rights reserved.
//

#import "HOTMemoListCell.h"

@implementation HOTMemoListCell

- (void)awakeFromNib
{
    _checkBtn.frame = CGRectMake(_checkBtn.frame.size.width *-1, _checkBtn.frame.origin.y, _checkBtn.frame.size.width, _checkBtn.frame.size.height);
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (IBAction)memoBtnClicked:(id)sender {
    
    if ([self.delegate respondsToSelector:@selector(memoDetailBtnClicked:)]) {
        
        [self.delegate memoDetailBtnClicked:self.indexPath];
    }
}

-(BOOL)isEdit {
    
    return isEdit;
}

-(void)setEdit:(BOOL)flg animated:(BOOL)animated{
    
    isEdit = flg;
    
    NSLayoutConstraint *radioBtnConstraint = nil;
    for (NSLayoutConstraint *cons in _bgView.constraints) {
        
        if (cons.firstItem == _checkBtn
            && cons.firstAttribute == NSLayoutAttributeLeading
            && cons.secondItem == _bgView
            && cons.secondAttribute == NSLayoutAttributeLeading) {
            
            radioBtnConstraint = cons;
            break;
        }
    }
    
    if (flg) {
        
        
        
        if (animated) {
            
            
            
            [UIView animateWithDuration:0.3 animations:^{
                
                radioBtnConstraint.constant = 14;
                [_bgView layoutIfNeeded];
            }];
        } else {
            
//            [UIView animateWithDuration:0.3 animations:^{
            
                radioBtnConstraint.constant = -25;
            
//            }];
        }
        
        
    } else {
        
        if (animated) {
            
            [UIView animateWithDuration:0.3 animations:^{
                
                radioBtnConstraint.constant = -25;
                [_bgView layoutIfNeeded];
            }];
        } else {
            
            radioBtnConstraint.constant = -25;
        }
    }
}

- (IBAction)checkBtnClicked:(UIButton *)sender {
    
    sender.selected = !sender.isSelected;
    
    if ([self.delegate respondsToSelector:@selector(selectedItem:indexPath:)]) {
        
        [self.delegate selectedItem:_checkBtn.isSelected indexPath:self.indexPath];
    }
}


-(void)setSelectedItem:(BOOL)selected {
    
    _checkBtn.selected = selected;
    
}

@end
